package com.jg.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jg.comm.responce.PageResult;
import com.jg.comm.responce.R;
import com.jg.model.dto.ProductQuery;
import com.jg.model.entity.Products;
import com.jg.model.vo.ProductVo;
import com.jg.service.ProductsService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 供应商商品信息表 前端控制器
 * </p>
 *
 * @author 86130
 * @since 2025-09-19 11:21
 */
@RestController
@RequestMapping("/products")
@Tag(name = "供应商商品信息表控制器")
public class ProductsController {

    @Autowired
    private ProductsService productsService;

    //分页查询获取商品列表
    @PostMapping("/page")
    @Schema(description = "分页查询获取商品列表")
    @Parameter(name = "productQuery", description = "商品查询参数")
    public R<PageResult<ProductVo>> getProductPage(ProductQuery productQuery) {
        PageResult<ProductVo> productsPage = productsService.getProductPage(productQuery);
        return R.success(productsPage);
    }

    @PostMapping("/edit")
    @Schema(description = "编辑商品")
    @Parameter(name = "products", description = "商品信息")
    public R editProduct(Products products, MultipartFile imageFile) {
        productsService.editProduct(products, imageFile);
        return R.success();
    }

    //通过商品id查询商品
    @GetMapping("/info/{productId}")
    @Schema(description = "通过商品id查询商品")
    @Parameter(name = "productId", description = "商品id")
    public R<Products> getInfo(@PathVariable Integer productId) {
        Products product = productsService.getById(productId);
        return R.success(product);
    }

}
